package cn.java76.spring1.aop;

import org.springframework.stereotype.Service;

import java.util.*;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
//模拟Student的操作
@Service
public class StudentService {
    private static Map<Long,Student> stus=new HashMap<>();
    static{
        stus.put(1L,new Student(1L,"老吴","139383883"));
        stus.put(2L,new Student(2L,"老张","1363534"));
        stus.put(3L,new Student(3L,"老马","137345345"));
        stus.put(4L,new Student(4L,"小宋","174345345345"));
        stus.put(5L,new Student(5L,"admin","174345345345"));
    }
    public Student get(long stuno){
        return stus.get(stuno);
    }
    public int add(Student s){
        long start=System.nanoTime();
        System.out.println("在StudentService中，准备往数据库加入新生"+s.getName());
        stus.put(s.getStuno(),s);
        long end=System.nanoTime();
        //.............
        //System.out.println(end-start);
        return 1;
    }
    public int update(Student s){
        stus.put(s.getStuno(),s);
        return 1;
    }

    public boolean del(long stuno){
       return  stus.remove(stuno)!=null;

    }
    public List<Student> findAll(){
        return new ArrayList<>(stus.values());
    }
}
